home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / glchess / scene / human.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  4.8 KB  |  139 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''
  5. '''
  6. __author__ = 'Robert Ancell <bob27@users.sourceforge.net>'
  7. __license__ = 'GNU General Public License Version 2'
  8. __copyright__ = 'Copyright 2005-2006  Robert Ancell'
  9. import glchess.scene as glchess
  10.  
  11. class SceneHumanInput:
  12.     '''
  13.     '''
  14.     __inputEnabled = True
  15.     __startSquare = None
  16.     __showHints = True
  17.     
  18.     def __init__(self):
  19.         '''Constructor for a scene with human selectable components'''
  20.         pass
  21.  
  22.     
  23.     def onRedraw(self):
  24.         '''This method is called when the scene needs redrawing'''
  25.         pass
  26.  
  27.     
  28.     def playerIsHuman(self):
  29.         '''Check if the current player is a human.
  30.         
  31.         Return True the current player is human else False.
  32.         '''
  33.         return False
  34.  
  35.     
  36.     def getSquare(self, x, y):
  37.         """Find the chess square at a given 2D location.
  38.         
  39.         'x' is the number of pixels from the left of the scene to select.
  40.         'y' is the number of pixels from the bottom of the scene to select.
  41.         
  42.         Return the co-ordinate as a tuple in the form (file,rank) or None if
  43.         no square at this point.
  44.         """
  45.         pass
  46.  
  47.     
  48.     def squareIsFriendly(self, coord):
  49.         '''Check if a given square contains a friendly piece.
  50.         
  51.         Return True if this square contains a friendly piece.
  52.         '''
  53.         return False
  54.  
  55.     
  56.     def canMove(self, start, end):
  57.         """Check if a move is valid.
  58.         
  59.         'start' is the location to move from in LAN format (string).
  60.         'end' is the location to move from in LAN format (string).
  61.         """
  62.         return False
  63.  
  64.     
  65.     def moveHuman(self, start, end):
  66.         """Called when a human player moves.
  67.         
  68.         'start' is the location to move from in LAN format (string).
  69.         'end' is the location to move from in LAN format (string).
  70.         """
  71.         pass
  72.  
  73.     
  74.     def enableHumanInput(self, inputEnabled):
  75.         """Enable/disable human input.
  76.         
  77.         'inputEnabled' is a flag to show if human input is enabled (True) or disabled (False).
  78.         """
  79.         if inputEnabled is False:
  80.             self._SceneHumanInput__selectSquare(None)
  81.         
  82.         self._SceneHumanInput__inputEnabled = inputEnabled
  83.  
  84.     
  85.     def select(self, x, y):
  86.         '''
  87.         '''
  88.         if self._SceneHumanInput__inputEnabled is False:
  89.             return None
  90.         if self.playerIsHuman() is False:
  91.             return None
  92.         coord = self.getSquare(x, y)
  93.         if coord is None:
  94.             return None
  95.         if self._SceneHumanInput__startSquare == coord:
  96.             self._SceneHumanInput__selectSquare(None)
  97.             return None
  98.         if self.squareIsFriendly(coord):
  99.             self._SceneHumanInput__selectSquare(coord)
  100.         elif self._SceneHumanInput__startSquare is not None:
  101.             self._SceneHumanInput__move(self._SceneHumanInput__startSquare, coord)
  102.         
  103.         self.onRedraw()
  104.         return coord
  105.  
  106.     
  107.     def deselect(self, x, y):
  108.         '''
  109.         '''
  110.         if self._SceneHumanInput__inputEnabled is False:
  111.             return None
  112.         if self.playerIsHuman() is False:
  113.             return None
  114.         coord = self.getSquare(x, y)
  115.         if coord is None:
  116.             return None
  117.         self.onRedraw()
  118.         return coord
  119.  
  120.     
  121.     def __selectSquare(self, coord):
  122.         if self._SceneHumanInput__startSquare == coord:
  123.             return None
  124.         self._SceneHumanInput__startSquare = coord
  125.         self.selectSquare(coord)
  126.  
  127.     
  128.     def __move(self, start, end):
  129.         '''Attempt to make a move.
  130.         
  131.         ...
  132.         '''
  133.         if self.canMove(start, end) is False:
  134.             return None
  135.         self._SceneHumanInput__selectSquare(None)
  136.         self.moveHuman(start, end)
  137.  
  138.  
  139.